package mycompiler.lexicalAnalysis;

import junit.framework.TestCase;
import mycompiler.lexicalAnalysis.*;

public class TokenProduceTestUpdate2 extends TestCase {

	TokenProduce tp;
	String s;
	
	protected void setUp() throws Exception {
		tp = new TokenProduce(s);
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testGetTokenlist() {
		tp.EOF = true;
		String str1 = "program x";
		String str2 = "x";
		
		assertEquals(this.forTestGetTokenList(str1, str2), false);
	}

	public void testReturnTokenlist() {
		tp.Tokennum = 1;
		
		TokenNode rightTn = new TokenNode();
		this.initTokenNode(rightTn, "1", "2", "3");
		String rightStr = " 1:2,3\n";
		
		TokenNode wrongTn = new TokenNode();
		this.initTokenNode(wrongTn, "1", "a", null);
		String wrongStr = "asd";
		
		//for no "for(){}"'s working;
		assertEquals(this.forTestReturnTokenList(), true);
		
		//
		assertEquals(this.forTestReturnTokenList(rightTn, rightStr), false);
		//System.out.println(tp.returnTokenlist(rightTn));
		
		//
		assertEquals(this.forTestReturnTokenList(wrongTn, wrongStr), false);
	}

	//test when the for(){} in ReturnTokenList doesn't execute,the result is right or wrong;
	public boolean forTestReturnTokenList()
	{
		String spaceStr = " ";
		TokenNode tn = new TokenNode();
		tp.Tokennum = 0;
		if(tp.returnTokenlist(tn).equals(spaceStr))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public void initTokenNode(TokenNode tn, String str1, String str2, String str3)
	{
		tn.Token.lineshow = Integer.parseInt(str1);
		tn.Token.Lex = str2;
		tn.Token.Sem = str3;
	}
	
	public boolean forTestReturnTokenList(TokenNode tn, String str)
	{
		if(tp.returnTokenlist(tn).equals(str))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	//
	public boolean forTestGetTokenList(String str1, String str2)
	{
		if(tp.getTokenlist(str1).equals(str2))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
